package com.common.core.results;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.common.core.exception.code.BaseErrorCode;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.io.Serializable;

/**
 * @auther zhangwj
 * @date 2021/7/26 下午1:48
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class VoidResult extends Result implements Serializable {

    private static final long serialVersionUID = 1L;

    VoidResult() {
    }

    public static VoidResult of() {
        return voidResult();
    }

    public static VoidResult failed(int errNum, String errMsg) {
        VoidResult response = new VoidResult();
        response.setSuccess(false);
        response.setErrNum(errNum);
        response.setErrMsg(errMsg);
        return response;
    }

    public static VoidResult failed(BaseErrorCode errorCode) {
        VoidResult response = new VoidResult();
        response.setSuccess(false);
        response.setErrNum(errorCode.getErrNum());
        response.setErrMsg(errorCode.getErrMsg());
        return response;
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this, SerializerFeature.WriteMapNullValue);
    }
}
